const http = require('http');
http.createServer((req, res) => {
  if (req.url === '/') {
    let cookies = req.headers.cookie;
    let visit = 0;
    if (cookies) {
      visit = Number(cookies.split('=')[1]);
    }
    visit++;
    res.setHeader('Set-Cookie', [`visit=${visit}`]);
    res.setHeader('Content-Type', 'text/plain;charset=UTF-8');
    res.end(`这是你的第${visit}次访问`);
  } else {
    res.end('Not Found');
  }
}).listen(8080, () => console.log('server is started on port 8080'));